﻿
    using Chain.BLL;
    using System;
    using System.Data;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using Wuqi.Webdiyer;

    public partial class ExchangeVerify : PageBase
    {

        private readonly Chain.IDAL.GiftExchange dal = new Chain.IDAL.GiftExchange();
        public DataSet GetVerifyListSP(int PageSize, int PageIndex, out int resCount, params string[] strWhere)
        {
            return this.dal.GetVerifyListSP(PageSize, PageIndex, out resCount, strWhere);
        }
        protected void BindExchangeList()
        {
            GiftExchange bllGiftExchange = new GiftExchange();
            int Counts = this.NetPagerParameter.RecordCount;
            string strSql = " GiftExchange.MemID=Mem.MemID and ExchangeStatus=1 ";
            if (base._UserShopID != 1)
            {
                strSql = PubFunction.GetShopAuthority(base._UserShopID, "ShopID", strSql);
            }
            DataTable dtGiftExchange = GetVerifyListSP(this.NetPagerParameter.PageSize, this.NetPagerParameter.CurrentPageIndex, out Counts, new string[] { strSql }).Tables[0];
            this.NetPagerParameter.RecordCount = Counts;
            this.NetPagerParameter.CustomInfoHTML = string.Format("<div class=\"results\"><span>当前第{0}/{1}页 共{2}条记录 每页{3}条</span></div>", new object[] { this.NetPagerParameter.CurrentPageIndex, this.NetPagerParameter.PageCount, this.NetPagerParameter.RecordCount, this.NetPagerParameter.PageSize });
            this.rptExchangeVerify.DataSource = dtGiftExchange;
            this.rptExchangeVerify.DataBind();
            PageBase.BindSerialRepeater(this.rptExchangeVerify, this.NetPagerParameter.PageSize * (this.NetPagerParameter.CurrentPageIndex - 1));
        }

        protected void drpPageSize_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.NetPagerParameter.CurrentPageIndex = 1;
            this.NetPagerParameter.PageSize = int.Parse(this.drpPageSize.SelectedValue);
            this.BindExchangeList();
        }

        protected void NetPagerParameter_PageChanging(object src, PageChangingEventArgs e)
        {
            this.NetPagerParameter.CurrentPageIndex = e.NewPageIndex;
            this.BindExchangeList();
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.BindExchangeList();
        }

        protected void rptMemGiftList_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
            {
                string name5;
                DataRowView dr = (DataRowView) e.Item.DataItem;
                Repeater rptItem = (Repeater) e.Item.FindControl("rptExchangeVerifyDetail");
                if (rptItem != null)
                {
                    GiftExchangeDetail bllGiftDetail = new GiftExchangeDetail();
                    int recordCount = this.NetPagerParameter.RecordCount;
                    string strSql = " GiftExchangeDetail.ExchangeGiftID=PointGift.GiftID ";
                    strSql = strSql + " and GiftExchangeDetail.ExchangeID=" + dr["ExchangeID"].ToString();
                    DataTable dtGiftDetail = bllGiftDetail.GetList(strSql).Tables[0];
                    rptItem.DataSource = dtGiftDetail;
                    rptItem.DataBind();
                    foreach (RepeaterItem rp in rptItem.Items)
                    {
                        Label lblDetailNum = (Label) rp.FindControl("lblDetailNumber");
                        lblDetailNum.Text = (rp.ItemIndex + 1).ToString();
                    }
                }
                Label lblStatus = (Label) e.Item.FindControl("lblExchangeStatus");
                if ((lblStatus != null) && ((name5 = dr["ExchangeStatus"].ToString()) != null))
                {
                    if (!(name5 == "1"))
                    {
                        if (!(name5 == "2"))
                        {
                            if (name5 == "3")
                            {
                                lblStatus.Text = "退回";
                            }
                            return;
                        }
                    }
                    else
                    {
                        lblStatus.Text = "待审核";
                        return;
                    }
                    lblStatus.Text = "通过审核";
                }
            }
        }
    }


